package edu.cs.usask.ca.silver.plugin.rcp.handlers.ui;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;

import edu.cs.usask.ca.silver.plugin.rcp.views.projectviewer.CustomProjectView;
import edu.cs.usask.ca.silver.plugin.rcp.views.projectviewer.ProjectView;
import edu.cs.usask.ca.silver.plugin.rcp.views.projectviewer.ProjectViewI;

/**
 * This command class is used to refresh the tree viewer representing the items
 * in the database. When existing data or model objects are add to the database,
 * this action is called to keep the user aware of the current state of the
 * object in the database.
 * 
 * This class needs to be expanded to only refreshing branches and to store the
 * current state of the tree viewer (the branches that are expanded stay
 * expanded)
 * 
 * @author Yudi Xue
 * 
 */
public class RefreshProjectViewTreehandler extends AbstractHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		ProjectViewI view = (ProjectViewI) HandlerUtil
				.getActiveWorkbenchWindow(event).getActivePage()
				.findView(event.getParameter("projectviewid"));
		

		view.refresh();

		return null;
	}

}
